# 使用power_aperture函数绘制fig1_16图形
import math
import matplotlib.pyplot as plt
import numpy as np
from irlab.basics.radar import Radar


# Reproduce Fig. 1.16a
tsc = 2.5
sigma = 0.1
te = 900.0
snr = 15
nf = 6.0
loss = 7.0
az_angle = 2
el_angle = 2
range_km = np.linspace(20, 250, 1000)
range_m = range_km * 1000
pap1 = Radar.power_aperture(snr, tsc, sigma/10, range_m, te, nf, loss, az_angle, el_angle)
pap2 = Radar.power_aperture(snr, tsc, sigma, range_m, te, nf, loss, az_angle, el_angle)
pap3 = Radar.power_aperture(snr, tsc, sigma*10, range_m, te, nf, loss, az_angle, el_angle)

plt.figure(1)
plt.plot(range_km, pap1, 'k', range_km, pap2, 'k-.', range_km, pap3, 'k:')
plt.grid()
plt.legend(['σ = -20 dBsm', 'σ = -10dBsm', 'σ = 0 dBsm'])
plt.xlabel('Detection range in Km')
plt.ylabel('Power aperture product in dB')

# Reproduce Fig. 1.16b
lambda_ = 0.03
G = 45
ae = np.linspace(1, 25, 1000)
Ae = 10 * np.log10(ae)
range_of_interest = 250e3
pap1 = Radar.power_aperture(snr, tsc, sigma/10, range_of_interest, te, nf, loss, az_angle, el_angle)
pap2 = Radar.power_aperture(snr, tsc, sigma, range_of_interest, te, nf, loss, az_angle, el_angle)
pap3 = Radar.power_aperture(snr, tsc, sigma*10, range_of_interest, te, nf, loss, az_angle, el_angle)
Pav1 = pap1 - Ae
Pav2 = pap2 - Ae
Pav3 = pap3 - Ae

plt.figure(2)
plt.plot(ae, Pav1, 'k', ae, Pav2, 'k-.', ae, Pav3, 'k:')
plt.grid()
plt.xlabel('Aperture size in square meters')
plt.ylabel('Pav in dB')
plt.legend(['σ = -20 dBsm', 'σ = -10dBsm', 'σ = 0 dBsm'])

# Show the figures
plt.show()
